package com.lanlian.commonlib.data;


import com.lanlian.commonlib.bean.BaseResponse;

import java.util.ArrayList;

/**
 * <pre>
 *
 *     date   : 2018/8/24 19:56
 *     desc   :市场返回对象
 *     version: 1.0
 * </pre>
 */
public class RespMarket extends BaseResponse {

    private ArrayList<GoodsBean> goodsList;
    private ArrayList<MarketBean> marketList;
    private ArrayList<ContractBean> contractList;

    public RespMarket() {
        this.goodsList = new ArrayList<>();
        this.marketList = new ArrayList<>();
        this.contractList = new ArrayList<>();
    }

    public ArrayList<GoodsBean> getGoodsList() {
        return goodsList;
    }

    public void setGoodsList(ArrayList<GoodsBean> goodsList) {
        this.goodsList = goodsList;
    }

    public ArrayList<MarketBean> getMarketList() {
        return marketList;
    }

    public void setMarketList(ArrayList<MarketBean> marketList) {
        this.marketList = marketList;
    }

    public ArrayList<ContractBean> getContractList() {
        return contractList;
    }

    public void setContractList(ArrayList<ContractBean> contractList) {
        this.contractList = contractList;
    }

    /**
     * 根据合约号得到合约
     *
     * @param contractNo
     * @return
     */
    public ContractBean getContract(String contractNo) {
        ContractBean mb = null;

        for (int i = 0; i < contractList.size(); i++) {
            if (contractNo.equals(contractList.get(i).contractNo)) {
                mb = contractList.get(i);
                break;
            }
        }
        return mb;
    }

    /**
     * 根据合约好得到市场
     *
     * @param contractNo
     * @return
     */
    public MarketBean getMarket(String contractNo) {
        MarketBean mb = null;
        if(marketList==null)
        {
            return mb;
        }
        String id = getMarketId(contractNo);
        if(id==null)
        {
            return mb;
        }
        for (int i = 0; i < marketList.size(); i++) {
            if (id.equals(marketList.get(i).id)) {
                mb = marketList.get(i);
                break;
            }
        }
        return mb;
    }

    /**
     * 合约号得到 市场id
     *
     * @param contractNo
     * @return
     */
    public String getMarketId(String contractNo) {
        String id = null;
        for (int i = 0; i < contractList.size(); i++) {
            if (contractNo.equals(contractList.get(i).contractNo)) {
                id = contractList.get(i).marketId;
                break;
            }
        }
        return id;
    }

    /**
     * 合约号得到 商品id
     *
     * @param contractNo
     * @return
     */
    public String goodsId(String contractNo) {
        if (contractNo == null) {
            return null;
        }
        String id = null;
        for (int i = 0; i < contractList.size(); i++) {
            if (contractNo.equals(contractList.get(i).contractNo)) {
                id = contractList.get(i).goodsId;
                break;
            }
        }
        return id;
    }

    /**
     * 合约号得到 商品
     *
     * @param contractNo
     * @return
     */
    public GoodsBean getGoods(String contractNo) {
        GoodsBean gb = null;
        String goodsId = goodsId(contractNo);
        if (goodsId == null) {
            return gb;
        }
        for (int i = 0; i < goodsList.size(); i++) {
            if (goodsId.equals(goodsList.get(i).id)) {
                gb = goodsList.get(i);
                break;
            }
        }
        return gb;
    }
}
